<%- title t('scripts.history_title', :script_name => @script.name(I18n.locale)) %>
<%- description 'Version history for ' + @script.name(I18n.locale) %>

<% 
show_diff = @script.script_versions.length > 1
show_all_versions = !params[:show_all_versions].nil?
visible_version_index = 0
svs = @script.script_versions.reverse
if show_diff
	if !show_all_versions %>
		<p><%=t('scripts.history_only_code_changes_info')%> <%=link_to t('scripts.history_all_changes_link'), :show_all_versions => 1%></p>
	<% else %>
		<p><%=t('scripts.history_all_changes_info')%> <%=link_to t('scripts.history_only_code_changes_link'), :show_all_versions => nil%></p>
	<% end
end %>
<form action="<%=script_diff_path(params[:script_id])%>">
	<% if show_diff %>
		<%= submit_tag t('scripts.diff_button'), :name => nil%>
	<% end %>
	<ul>
		<% svs.each_with_index do |sv, i|
			show_version = show_all_versions || ((i + 1 >= svs.length) || sv.rewritten_script_code_id != svs[i + 1].rewritten_script_code_id)
			if show_version %>
				<li>
					<% if show_diff %>
						<input required type="radio" name="v1" value="<%=sv.id%>"<% if visible_version_index == 0%> checked<%end%>>
						<input required type="radio" name="v2" value="<%=sv.id%>"<% if visible_version_index == 1%> checked<%end%>>
					<% end
					visible_version_index += 1 %>
					<%=link_to 'v' + sv.version, script_path(sv.script, :version => sv.id), {:rel => :nofollow}%>
					<% if !current_user.nil? && current_user.moderator? %>
						<%=link_to 'Delete', script_script_version_delete_path(script_id: sv.script.id, script_version_id: sv.id) %>
					<% end %>
					<%=markup_date(sv.created_at)%>
					<% if !sv.changelog.nil? and !sv.changelog.empty? %>
						- <%=sv.changelog%>
					<% end %>
				</li>
			<% end
		end %>
	</ul>
	<% if show_diff %>
		<%= submit_tag t('scripts.diff_button'), :name => nil%>
	<% end %>
</form>
